
// ImageShowMFCDoc.cpp : implementation of the CImageShowMFCDoc class
//

#include "stdafx.h"
#include "ImageShowMFC.h"

#include "ImageShowMFCDoc.h"
#include "Image.h"
#include "Mesh.h"
#include "MeshIO.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CImageShowMFCDoc

IMPLEMENT_DYNCREATE(CImageShowMFCDoc, CDocument)

BEGIN_MESSAGE_MAP(CImageShowMFCDoc, CDocument)
END_MESSAGE_MAP()


// CImageShowMFCDoc construction/destruction

CImageShowMFCDoc::CImageShowMFCDoc()
{
	m_mesh = NULL;
	// TODO: add one-time construction code here
	m_model = new GraphicImageModel();

	int w = 256;
	int h = 256;
	HPMIP::Image::Size size(w,h);
	HPMIP::Image::Unit unit(1,1);
	unsigned char* pixels = new unsigned char[w*h];
	for(int i = 0; i < h; i++) 
	{
		for(int j = 0; j < w; j++)
			pixels[i*w + j] = (i*w + j) % 255;
	}
	HPMIP::Image *image = new HPMIP::Image(size,HPMIP::Image::Pixel::UChar,HPMIP::Image::Format::Grey,unit,pixels);
	int width = image->GetWidth();

	m_model->GetImageGraph()->SetImage(image);


	//mesh 
	m_mesh = new Mesh();
	HpmipIO::MeshIO io("stl_Default");
	io.SetMesh(m_mesh);
	io.SetMeshName("d:\\test.stl");
	io.Read();
	m_model->GetMeshGraph()->SetMesh(m_mesh);
	
}

CImageShowMFCDoc::~CImageShowMFCDoc()
{
	
}

BOOL CImageShowMFCDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}




// CImageShowMFCDoc serialization

void CImageShowMFCDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CImageShowMFCDoc diagnostics

#ifdef _DEBUG
void CImageShowMFCDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CImageShowMFCDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CImageShowMFCDoc commands
